package com.ruoyi.gwc.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SnowFlakeIDGenerator;
import com.ruoyi.gwc.domain.TApprovalApply;
import com.ruoyi.gwc.domain.TDispatchVehicles;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.gwc.mapper.TVehicleApplicationMapper;
import com.ruoyi.gwc.domain.TVehicleApplication;
import com.ruoyi.gwc.service.ITVehicleApplicationService;

import static com.ruoyi.common.utils.SecurityUtils.getUsername;

/**
 * 用车申请Service业务层处理
 * 
 * @author wp
 * @date 2024-11-18
 */
@Service
public class TVehicleApplicationServiceImpl extends ServiceImpl<TVehicleApplicationMapper, TVehicleApplication> implements ITVehicleApplicationService{
    private static final Logger log = LoggerFactory.getLogger(TVehicleApplicationServiceImpl.class);

    @Autowired
    private TVehicleApplicationMapper tVehicleApplicationMapper;

    /**
     * 查询用车申请
     * 
     * @param applyId 用车申请主键
     * @return 用车申请
     */
    @Override
    public TVehicleApplication selectTVehicleApplicationByApplyId(Long applyId)
    {
        return tVehicleApplicationMapper.selectTVehicleApplicationByApplyId(applyId);
    }

    /**
     * 查询用车申请列表
     * 
     * @param tVehicleApplication 用车申请
     * @return 用车申请
     */
    @Override
    public List<TVehicleApplication> selectTVehicleApplicationList(TVehicleApplication tVehicleApplication)
    {
        return tVehicleApplicationMapper.selectTVehicleApplicationList(tVehicleApplication);
    }

    @Override
    public List<TVehicleApplication> selectTVehicleApplicationWithAllList(TVehicleApplication tVehicleApplication)
    {
        return tVehicleApplicationMapper.selectTVehicleApplicationWithAllList(tVehicleApplication);
    }

    @Override
    public List<TVehicleApplication> getVehicleApplicationList(Long vehicleId)
    {
        return tVehicleApplicationMapper.getVehicleApplicationList(vehicleId);
    }
    @Override
    public List<TVehicleApplication> getApprovalVehicleList(TApprovalApply approvalApply)
    {
        return tVehicleApplicationMapper.getApprovalVehicleList(approvalApply);
    }
    @Override
    public List<TVehicleApplication> getScheduledVehicleList(TDispatchVehicles dispatchVehicles)
    {
        return tVehicleApplicationMapper.getScheduledVehicleList(dispatchVehicles);
    }


    /**
     * 新增用车申请
     * 
     * @param tVehicleApplication 用车申请
     * @return 结果
     */
    @Override
    public int insertTVehicleApplication(TVehicleApplication tVehicleApplication)
    {
        tVehicleApplication.setCreateTime(DateUtils.getNowDate());
        tVehicleApplication.setCreateBy(getUsername());
        tVehicleApplication.setApplyId(SnowFlakeIDGenerator.getInstance().nextId());
        return tVehicleApplicationMapper.insertTVehicleApplication(tVehicleApplication);
    }

    /**
     * 修改用车申请
     * 
     * @param tVehicleApplication 用车申请
     * @return 结果
     */
    @Override
    public int updateTVehicleApplication(TVehicleApplication tVehicleApplication)
    {
        tVehicleApplication.setUpdateTime(DateUtils.getNowDate());
        tVehicleApplication.setUpdateBy(getUsername());
        return tVehicleApplicationMapper.updateTVehicleApplication(tVehicleApplication);
    }

    /**
     * 批量删除用车申请
     * 
     * @param applyIds 需要删除的用车申请主键
     * @return 结果
     */
    @Override
    public int deleteTVehicleApplicationByApplyIds(Long[] applyIds)
    {
        return tVehicleApplicationMapper.deleteTVehicleApplicationByApplyIds(applyIds);
    }

    /**
     * 删除用车申请信息
     * 
     * @param applyId 用车申请主键
     * @return 结果
     */
    @Override
    public int deleteTVehicleApplicationByApplyId(Long applyId)
    {
        return tVehicleApplicationMapper.deleteTVehicleApplicationByApplyId(applyId);
    }
}
